//
//  NetworkingManager.h
//  YiJuZhangShou
//
//  Created by 冷悦 on 16/3/3.
//  Copyright © 2016年 Uranus. All rights reserved.
//

#import <Foundation/Foundation.h>


typedef NS_ENUM(NSUInteger, RequestType){
    HTTP_PUT = 1,
    HTTP_POST = 2,
    HTTP_GET = 3,
    HTTP_DELETE = 4,
    HTTP_UPLOAD = 5
};

@class NetworkingBaseManager;

@protocol NetworkingBaseManagerAPISuccessCallbackDelegate <NSObject>

@required

- (void)manager:(NetworkingBaseManager *)manager callAPIDidSuccessWithParams:(NSDictionary *)responseParams; //服务器请求成功，映射返回结果，并更新UI界面

@end

@protocol NetworkingBaseManagerAPIFailureCallbackDelegate <NSObject>

- (void)manager:(NetworkingBaseManager *)manager callAPIDidError:(NSDictionary *)responseParams; // 服务器返回错误状态码时使用，纪录发送请求数据

- (void)manager:(NetworkingBaseManager *)manager callAPIDidFailed:(NSError *)error andTask:(NSURLSessionDataTask *)task; //http 错误使用，记录服务器的错误

@end

@protocol NetworkingBaseManagerValidator <NSObject>

@required
- (BOOL)isCorrectWithCallbackData:(NSDictionary *)data;//验证返回数据用
@optional
- (BOOL)isCorrectWithParamsData:(NSDictionary *)data;//验证发送数据用

@end

@protocol NetworkingBaseManagerInterceptor <NSObject>

@optional

- (void)beforePerformSuccess:(NSURLSessionDataTask *)task
                withResponse:(NSDictionary *)responseParams;//解析http header使用

- (void)manager:(NetworkingBaseManager *)manager afterPerformSuccessWithResponse:(NSDictionary *)responseParams; //清除RequestId用

- (void)manager:(NetworkingBaseManager *)manager beforePerformFailWithResponse:(NSError *)error; //在某些情况下可以界面上提示用户

- (void)manager:(NetworkingBaseManager *)manager afterPerformFailWithResponse:(NSError *)error;//清除RequestId用

- (BOOL)shouldCallAPIWithManager:(NetworkingBaseManager *)manager;//更新http header使用

- (void)afterCallingAPIWithManager:(NetworkingBaseManager *)manager;//纪录操作日志用

@end

@interface NetworkingBaseManager : NSObject

@property (nonatomic, strong)NSString *apiName; //发送的API地址

@property (nonatomic, assign)RequestType requestType; //发送请求的类型

@property (nonatomic, strong)NSDictionary *params; //发送的数据

@property (nonatomic, assign)BOOL isCacheResponse; // 是否需要缓存数据

@property (nonatomic, assign)NSTimeInterval timeInterval; //缓存数据的时间

@property (nonatomic, assign)NSInteger tag; //manager 的编号

@property (nonatomic, strong, readonly) AFHTTPSessionManager *manger;

@property (nonatomic, weak) id<NetworkingBaseManagerAPISuccessCallbackDelegate> successDelegate;

@property (nonatomic, weak) id<NetworkingBaseManagerAPIFailureCallbackDelegate> failureDelegate;

@property (nonatomic, weak) id<NetworkingBaseManagerValidator> validator;

@property (nonatomic, weak) id<NetworkingBaseManagerInterceptor> interceptor;

/**上传图片对象*/
@property (nonatomic, strong) UIImage *postImage;
/**上传图片的文件名（可为空）*/
@property (nonatomic, copy) NSString *avatarFileName;

- (void)loadRequest;

@end
